package com.morningstar.system.controller.result;

import com.morningstar.system.dao.entity.SysMenu;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author yanglianshan
 */
@Getter
@Setter
public class Menu {

    private String path;

    private String name;

    private Long menuId;

    private String menuName;

    private String component;

    private Meta meta;

    private Object props;

    private List<Menu> children;

    public static Menu convert(SysMenu sysMenu) {
        Meta meta = new Meta();
        meta.setIcon(sysMenu.getIcon());
        meta.setLocale(sysMenu.getMenuName());
        meta.setOrder(sysMenu.getOrderNum());
        meta.setHideInMenu(StringUtils.equalsIgnoreCase(sysMenu.getVisible(), "0"));
        meta.setIgnoreCache(StringUtils.equalsIgnoreCase(sysMenu.getIsRefresh(), "1"));
        meta.setRequiresAuth(true);
        Menu menu = new Menu();
        menu.setName(sysMenu.getRouteName());
        menu.setMenuId(sysMenu.getMenuId());
        menu.setMenuName(sysMenu.getMenuName());
        menu.setComponent(sysMenu.getRouteComponent());
        menu.setPath(sysMenu.getRoutePath());
        menu.setProps(sysMenu.getRouteProps());
        menu.setMeta(meta);
        return menu;
    }

    @Getter
    @Setter
    static public class Meta {

        private String[] roles;

        private boolean requiresAuth;

        private String icon;

        private String locale;

        private boolean hideInMenu;

        private boolean hideChildrenInMenu;

        private String activeMenu;

        private Integer order;

        private boolean noAffix;

        private boolean ignoreCache;
    }
}
